package com.cl.short_video_java.web.log;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cl.short_video_java.annotation.IsRole;
import com.cl.short_video_java.annotation.Log;
import com.cl.short_video_java.annotation.Login;
import com.cl.short_video_java.common.Const;
import com.cl.short_video_java.common.Result;
import com.cl.short_video_java.mapper.SysLogininforMapper;
import com.cl.short_video_java.menum.BusinessType;
import com.cl.short_video_java.pojo.SysLogininfor;
import com.cl.short_video_java.service.SysLogininforService;
import com.cl.short_video_java.util.ExceUtil;
import com.cl.short_video_java.vo.sys.LoginInforExceSearch;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.text.SimpleDateFormat;

@RestController
@RequestMapping("/login_infor")
public class SysLoginInforController {
	@Resource
	private SysLogininforService sysLogininforService;
	@Resource
	private SysLogininforMapper sysLogininforMapper;
	private ExceUtil ExcelUtil;

	/**
	 * 删除指定的id登录日志
	 *
	 * @param idlist
	 * @return boolean
	 */
	@PostMapping("/remove")
	@Log(title = "登录日志", businessType = BusinessType.DELETE)
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 13)
	public Result removeLogininfor(@RequestParam("idlist") String idlist) {
		return Result.success(sysLogininforService.removeLogininforService(idlist));
	}

	/**
	 * 清除所有登录日志数据
	 *
	 * @return boolean
	 */

	@PostMapping("/clear")
	@Log(title = "清空登录日志", businessType = BusinessType.OTHER)
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 13)
	public Result clearLogininfor() {
		return Result.success(sysLogininforService.clearLoginInforService());
	}

	/**
	 * 分页查询（包含了搜索）
	 *
	 * @param loginInforExceSearch
	 * @return
	 */
	@PostMapping("/page")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 13)
	public Result pageLogininfor(@RequestBody LoginInforExceSearch loginInforExceSearch) {
		return Result.success(sysLogininforService.pageLogininforService(loginInforExceSearch));
	}

	/**
	 * 首页的登录日志获取
	 *
	 * @param num
	 * @param size
	 * @return
	 */
	@GetMapping("/list")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 13)
	public Result getList(@RequestParam("num") Integer num, @RequestParam("size") Integer size) {
		return Result.success(sysLogininforService.homePage(num, size));
	}

	/**
	 * 数据导出
	 *
	 * @param loginInforSearch
	 * @return
	 * @throws IOException
	 */
	@PostMapping("/exce")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 13)
	public ResponseEntity<byte[]> getExce(@RequestBody LoginInforExceSearch loginInforSearch) throws IOException {
		return sysLogininforService.getExceService(loginInforSearch);
	}

}
